# 加载数据
from keras.preprocessing.image import load_img,img_to_array
img_path = '1.jpg'
img = load_img(img_path,target_size=(224,224))
img = img_to_array(img)
# print(type(img),img.shape)

# 使用VGG16提取图像特征
from keras.applications.vgg16 import VGG16,preprocess_input
import numpy as np
model_vgg = VGG16(weights='imagenet',include_top=False)
x = np.expand_dims(img,axis=0)
x = preprocess_input(x)
# print(x.shape)

# 特征提取
feature_vgg = model_vgg.predict(x)
# print(feature_vgg.shape)
# flatten
feature_vgg = feature_vgg.reshape(1,7*7*512)
# print(feature_vgg.shape)

# 画图
from matplotlib import pyplot as plt
plt.figure(figsize=(10,10))
img = load_img(img_path,target_size=(224,224))
plt.imshow(img)
plt.show()